import request from "@/utils/request";

const nimApi = {
  /**
   * 注册账号
   * @param data.userId 用户id
   * @param data.terminal 用户终端,可用值:PLATFORM,MERCHANT,CUSTOMER
   * @returns {*}
   */
  registerNimApi(data) {
    return request({
      url: `/merchant/im/user/register`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取appKey等信息
   * @param data
   */
  getConfigApi(data) {
    return request({
      url: `/merchant/im/base/getConfig`,
      method: "post",
      data: data,
    });
  },
  getByLoginApi(data) {
    return request({
      url: `/im/user/getByLogin`,
      method: "get",
      data: data,
    });
  },
  /**
   * 创建会话
   * @param data
   */
  createConversationApi(data) {
    return request({
      url: `/merchant/im/conversation/create`,
      method: "post",
      data: data,
    });
  },
  /**
   * 查询当前登录会话列表
   * @param data
   */
  getConversationApi(data) {
    return request({
      url: `/merchant/im/conversation/page`,
      method: "post",
      data: data,
    });
  },
  /**
   * 同步会话数据
   * @param data.conversationId 会话id
   */
  syncConversationApi(data) {
    return request({
      url: `/merchant/im/conversation/sync`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取聊天记录
   * @param data
   */
  getChatHistoryApi(data) {
    return request({
      url: `/merchant/im/message/pageByMongo`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取聊天记录
   * @param data
   */
  syncChatHistoryApi(data) {
    return request({
      url: `/merchant/im/message/sync`,
      method: "post",
      data: data,
    });
  },
  /**
   * 删除聊天记录
   * @param data.conversationId 会话id
   * @param data.messageServerId 服务端消息 ID
   */
  syncRemoveChatHistoryApi(data) {
    return request({
      url: `/merchant/im/message/syncRemove`,
      method: "post",
      data: data,
    });
  },
  /**
   * 查询聊天记录 通过云信
   * @param data
   */
  getChatHistoryByYxApi(data) {
    return request({
      url: `/merchant/im/conversation/mockPage`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取appkey等配置
   * @param data
   */
  getChatConfigApi(data) {
    return request({
      url: `/merchant/im/base/getConfig`,
      method: "post",
      data: data,
    });
  },
  consultServiceApi(data) {
    return request({
      url: `/merchant/im/base/consultService`,
      method: "post",
      data,
    });
  },
  /**
   * 获取指定会话的房屋信息
   * @param params IMQueryParams
   */
  getConversationHouses(params: IMQueryParams) {
    return request({
      url: `/merchant/im/base/getConversationHouses`,
      method: "get",
      params,
    });
  },
  /**
   * 获取指定会话的资料信息
   * @param params
   */
  getConversationProfile(params: CustomerRelationQuery) {
    return request({
      url: `/im/getConversationProfile`,
      method: "get",
      params,
    });
  },
  /**
   * 获取平台端客服im账号
   */
  getServices() {
    return request({
      url: `/im/user/getServices`,
      method: "get",
    });
  },
};

export default nimApi;

/**
 * IM 消息查询参数
 */
export interface IMQueryParams {
  /** 发送者 IM 账号 */
  senderId: string;

  /** 接收者 IM 账号 */
  receiverId: string;

  /** 发送者主键 ID */
  senderUserId?: string;

  /** 接收者主键 ID */
  receiverUserId?: string;
}

/**
 * 客户关系查询参数
 */
export interface CustomerRelationQuery {
  /** 客户关系 ID */
  id?: string;

  /** 机会来源（1-设计机会，2-建材机会） */
  opportunitySource?: string;

  /** 接收者 IM 账号 */
  receiverId?: string;
}
